/*
题目：第三大的数
给你一个非空数组，返回此数组中 第三大的数 。如果不存在，则返回数组中最大的数。
 */
public class ThirdMax {
    public int thirdMax(int[] nums) {
        long one = Long.MIN_VALUE;
        long two = Long.MIN_VALUE;
        long three = Long.MIN_VALUE;
        for(int num : nums){
            if(num > one){
                three = two;
                two = one;
                one = num;
            }else if(num > two && num < one){
                three = two;
                two = num;
            }else if(num > three && num < two){
                three = num;
            }
        }
        return three == Long.MIN_VALUE? (int)one: (int)three;
    }
}
